package cn.tedu.charging.order.controller;

import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.order.pojo.param.OrderAddParam;
import cn.tedu.charging.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单接口
 */
@Api(tags = "订单接口")
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * 创建订单
     * @param orderAddParam
     * @return
     */
    @ApiOperation("创建订单")
    @PostMapping("create")
    public JsonResult createOrder(@RequestBody @Validated OrderAddParam orderAddParam) throws Exception{
        //因为用小刀生成的API文档测试，传到后端都是json格式，所以加RequestBody注解。毕竟不是智慧车辆前端用axios传参

        log.debug("订单创建的入参-{}",orderAddParam);
        //xxx 别的代码有可能修改了入参，加个日志进行查看

        //创建类型的接口是否返回结果,要根据业务来决定,如果后续的业务要基于返回的id
        //做其他的操作,比如查看详情,这个返回的id,可以作为查看订单详情的入参
        log.debug("创建订单调用service的入参-{}",orderAddParam);
        String orderNo = orderService.createOrder(orderAddParam);
        log.debug("创建订单调用service的入参-{},出参-{}",orderAddParam,orderNo);

        return JsonResult.ok("订单创建成功");

    }
}
